<template>
	<!-- 添加车辆 -->
	<view class="addCar">
		<u-navbar title="运单信息发布" title-color="#333" back-icon-color="#333"></u-navbar>
		<view class="addCar-bottom">
			<view class="zx-addres">
				<!-- <view class="title u-line-2"><span class="zhuang-huo-dizhi">装</span><input class="addCar-input-one"
						type="text" placeholder="请输入装货地址" v-model="zxobj.zhdz" /></view> -->
				<!-- <view class="title u-line-2"><span class="xie-huo-dizhi">卸</span><input class="addCar-input-one"
						type="text" placeholder="请输入卸货地址" v-model="zxobj.xhdz" /></view> -->
				<view class="xh-text" style="line-height: 200rpx;">
					<span class="xie-huo-dizhi">卸</span>
				</view>
				<!-- <picker class="addCar-input-one" style="width: 100% !important;" @change="bindxhPickerChange" :value="zxobj.xhdz" :range="xhArray"
					range-key="ORMTB404CA00">
					<i class="addCar-phone-placeholder" v-if="zxobj.xhdz<0">请选择配送地</i>
					<view v-else class="uni-input">{{xhArray[zxobj.xhdz].ORMTB404CA00}}</view>
				</picker> -->

				<view class="xhdz-xinxi" @click="xhdlistFun">
					<!-- <u-cell-group :title-style="styleCellGroup">
						<u-cell-item :title-style="styleCellGroup" class="ucell-item" :border-top="false"
							:border-bottom="false" :title="xhdztitle.ORMTB404CA00||'请选择收货地'">

						</u-cell-item>
					</u-cell-group> -->
					<view class="">
						<view class="" style="padding:10rpx; color:#DB9370">
							<text>{{xhdztitle.ORMTB404CA00||'&nbsp;'}}</text>
						</view>
						<view class="" style="padding-bottom:10rpx;">
							<text>{{xhdztitle.ORMTB404CA05||'请添加收货地址'}}</text>
						</view>
					</view>
					<view class="" style="line-height: 200rpx;">
						<u-icon name="arrow-right"></u-icon>
					</view>
				</view>

			</view>
			<view class="addCar-content-box">
				<view class="cx-box">
					<text class="addCar-phone">车型：</text>
					<u-radio-group v-model="cx" @change="radioGroupChange">
						<u-radio label-size="32" @change="radioChange" v-for="(item, index) in list1" :key="index"
							:name="item.name" :disabled="item.disabled" :checked="item.checked">
							{{item.name}}
						</u-radio>
					</u-radio-group>
					</checkbox-group>
				</view>
				
				<view class="addCar-carName-phone" v-if="userinfo.ORMTB410CB06=='1'">
					<text class="addCar-phone">账户：</text>
					<picker class="addCar-input-one" @change="bindPickerdfzhChange" :value="msgobj.dfzh" :range="dfzhArray"
						range-key="ZHNAME">
						<i class="addCar-phone-placeholder" v-if="msgobj.dfzh<0">请选择代发运单账户</i>
						<view v-else class="uni-input">{{dfzhArray[msgobj.dfzh].ZHNAME}}</view>
						<!-- <view v-else class="uni-input">{{cjArray[msgobj.wlcj].SETTB99CA00}}</view> -->
					</picker>
					<!-- <input class="addCar-input-one" type="text" placeholder="请选择厂家" v-model="msgobj.wlcj"
						maxlength="15" /> -->
				</view>
				
				<view class="addCar-carName-phone">
					<text class="addCar-phone">厂家：</text>
					<picker class="addCar-input-one" @change="bindPickerChange" :value="msgobj.wlcj" :range="cjArray"
						range-key="SETTB99CA00">
						<i class="addCar-phone-placeholder" v-if="msgobj.wlcj<0">请选择厂家</i>
						<view class="uni-input" v-if="zmcjdata.cjxs =='0'">{{zmcjdata.cjname}}</view>
						<view v-else class="uni-input">{{cjArray[msgobj.wlcj].SETTB99CA00}}</view>
						<!-- <view v-else class="uni-input">{{cjArray[msgobj.wlcj].SETTB99CA00}}</view> -->
					</picker>
					<!-- <input class="addCar-input-one" type="text" placeholder="请选择厂家" v-model="msgobj.wlcj"
						maxlength="15" /> -->
				</view>
				<view class="addCar-carName-phone">
					<text class="addCar-phone">物料类型：</text>
					<picker class="addCar-input-one" @change="bindPickerWlChange" :value="msgobj.wllx" :range="wlArray"
						range-key="settb109CA00_jg">
						<i class="addCar-phone-placeholder" v-if="msgobj.wllx<0">请选择物料</i>
						<view class="uni-input" v-if="zmcjdata.cjxs =='0'">{{zmcjdata.cjwlname}}</view>
						<view v-if="zmcjdata.cjxs =='2'" class="uni-input">{{wlArray[msgobj.wllx].settb109CA00}}
							<text style="padding-left:20rpx;color:red;">{{wlArray[msgobj.wllx].settb109CA01}}元</text>
						</view>
					</picker>
				</view>

				<view class="addCar-carName-phone">
					<text class="addCar-phone">发单运费价：</text>
					<input class="addCar-input-one" type="digit" placeholder="请输入" v-model="msgobj.fdyf"
						maxlength="15" />
					<text>每吨</text>
				</view>
				<view class="addCar-carName-phone">
					<text class="addCar-phone">接单运费价：</text>
					<input class="addCar-input-one" type="digit" placeholder="请输入" v-model="msgobj.yf" maxlength="15" />
					<text>每吨</text>
				</view>

				<view class="addCar-carName-phone">
					<text class="addCar-phone">亏吨范围：</text>
					<input class="addCar-input-one" type="digit" placeholder="请输入" v-model="msgobj.kd" maxlength="3" />
					<text style="padding-left: 10rpx;">吨</text>
				</view>
				<view class="addCar-carName-phone">
					<text class="addCar-phone">超时时间：</text>
					<input class="addCar-input-one" type="digit" placeholder="请输入" v-model="msgobj.cssj" />
					<text style="padding-left: 10rpx;">小时</text>
				</view>
				<view class="addCar-carName-phone">
					<text class="addCar-phone">车数：</text>
					<input class="addCar-input-one" type="number" placeholder="请输入车数" v-model="msgobj.cs"
						maxlength="15" />
					<text style="padding-left: 10rpx;">车</text>
				</view>
				<view class="addCar-carName-phone" v-if="userinfo.ORMTB410CB06=='1'">
					<text class="addCar-phone">管理费：</text>
					<input class="addCar-input-one" type="digit" placeholder="请输入管理费" v-model="msgobj.glf"/>
					<text style="padding-left: 10rpx;">%</text>
				</view>
				<view class="addCar-carName-phone" style="display: flex;">
					<text class="addCar-phone">是否公开：</text>
					<text class="addCar-input-one"></text>
					<u-switch v-model="isgk" size="40" @change="change"></u-switch>

					<view class="" style="padding-left: 10rpx;">
						<text style="color: #A8A8A8;" v-if="isgk ==false">否</text>
						<text style="color: #FF0000;" v-if="isgk ==true">是</text>
					</view>

				</view>
				<view class="addCar-carName-phone" style="display: flex;">
					<text class="addCar-phone">是否指定车辆：</text>
					<text class="addCar-input-one"></text>
					<u-switch v-model="iszdcl" size="40" @change="changecl"></u-switch>
					<view class="" style="padding-left: 10rpx;">
						<text style="color: #A8A8A8;" v-if="iszdcl ==false">否</text>
						<text style="color: #FF0000;" v-if="iszdcl ==true">是</text>
					</view>
				</view>
				<view class="addCar-carName-phone" style="display: flex;">
					<text class="addCar-phone">接单物料冻结：</text>
					<text class="addCar-input-one"></text>
					<u-switch v-model="isjdwl" size="40" @change="changejdwl"></u-switch>
					<view class="" style="padding-left: 10rpx;">
						<text style="color: #A8A8A8;" v-if="isjdwl ==false">否</text>
						<text style="color: #FF0000;" v-if="isjdwl ==true">是</text>
					</view>
				</view>

				<view class="addCar-carName-phone" style="border: none;" v-if="iszdcl==true">
					<text class="addCar-phone" style="width:193rpx;">车牌号：</text>
					<!-- <input class="addCar-input-one" type="text" v-model="carNumberIpt"/> -->
					<view class="addCar-phone-car" @click="boardClick">
						{{carNumberIpt}}
						<text></text>
						<i class="addCar-phone-placeholder" v-if="carNumberIpt==''">请输入车牌号</i>
					</view>
					<text @click="carShowFun" style="color: rgba(0, 161, 244, 1);">历史车牌</text>
				</view>
				<!-- v-if="iszdcl==false" -->

				<view class="wrap" v-if="carList.length>0" style="border-top: 1px solid rgba(230, 230, 230, 0.5);">
					<view class="addCar-carName-phone" style="border: none;" v-for="(item, index) in carList">
						<!-- <input class="addCar-input-one" type="text" v-model="carNumberIpt"/> -->
						<view class="addCar-phone-car">
							{{item.carPlate}}
						</view>
						<text v-if="item.carPlate" @click="delCar(item)" style="color: rgba(0, 161, 244, 1);">删除</text>
					</view>
				</view>


				<!-- 	<view class="add-phone-main">


					<view class="addCar-carName-phone" v-for="(item, index) in list">
						<text class="addCar-phone">联系方式：</text>
						<input class="addCar-input-one" type="number" @input="phoneIptInput" placeholder="请输入联系方式"
							v-model="item.phone" maxlength="11" />
						<span style="color: red;" v-if="list.length>=2" @click="delItem(item)">删除</span>

					</view>
					<view class="add-phone" @click="addItem">添加</view>
				</view> -->
				<!-- <view class="addCar-carName-phone">
					<text class="addCar-phone">皮重：</text>
					<input class="addCar-input-one" @input="tareIptInput" placeholder="请输入皮重" type="number"
						v-model="tareIpt" />
					<text class="addCar-dun">吨</text>
				</view> -->
			</view>
			<view class="text-jieshao">
				<text>{{remark}}</text>
				<!-- <view style="font-size: 20rpx; color: #D3D3D3;">确认收货后收取10元管理费！</view> -->
			</view>
			<!--  -->
			<view class="addCar-reset-determine">
				<!-- <view class="add-phone" @click="addItem">新增电话</view> -->
				<!-- <view class="addCar-reset" @click="reset">重置</view> -->
				<view class="addCar-determine" @click="determine">确定</view>
			</view>
		</view>
		<u-popup v-model="carshow" length="100%" mode="right" @close="carclose">
			<view class="iscar-nav">
				<view class="iscar-nav-top" v-if="platform==false"></view>
				<view v-else :style="{ height: systemInfo.statusBarHeight + 'px' }"></view>
				<view class="iscar-nav-search">
					<view class="iscar-nav-search-btn" @click="carshow=false">
						返回
					</view>
					<view class="iscar-nav-search-ipt">
						<u-search placeholder="请输入车牌号" @custom="carcustom" @change="valChange" @focus="focusFun"
							@blur="blurFun" v-model="carSearch" :show-action="true" :action-style="actionStyle"
							action-text="添加"></u-search>
					</view>
				</view>
				<view class="iscar-nav-btn">
					<view @click="checkedAll" v-if="ischeckedAll==true">全选</view>
					<view @click="nocheckedAll" v-if="ischeckedAll==false">全不选</view>
					<view @click="determineFun">确定</view>
				</view>
			</view>
			<!-- :style="platform==false?'padding-top: 24vh;':'padding-top: 14vh'" -->
			<view class="iscar-content" :style="{paddingTop:padingTop}">
				<view v-if="platform==true" :style="{ height: systemInfo.statusBarHeight + 'px' }"></view>
				<u-checkbox-group :wrap="false" width="350rpx" @change="checkboxGroupChange">
					<u-checkbox size='40' label-size="38" v-model="item.checked" v-for="(item, index) in carnumlist"
						:key="index" :name="item.name">{{item.name}}</u-checkbox>
				</u-checkbox-group>
			</view>
		</u-popup>
		<u-modal v-model="addCarLoginShow" content="请确认是否发布该运单" :show-cancel-button="true" @confirm="addCarNewConfirm">
		</u-modal>
		<u-keyboard ref="uKeyboard" mode="car" @change="carValChange" @confirm="sucAdd" @backspace="carBackspace"
			v-model="carshow1" :mask="false" :mask-close-able="false"></u-keyboard>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userinfo: JSON.parse(uni.getStorageSync('userinfo')),
				platform: uni.getStorageSync('platform'),
				// systemInfo:uni.getSystemInfoSync(),
				navHeight: '',
				carSearch: '',
				xhdztitle: {
					ORMTB404CA00: ''
				},
				xhdzqhID: 0,
				actionStyle: {
					backgroundColor: '#00a1f1',
					color: '#FFF',
					width: '100rpx',
					height: '60rpx',
					lineHeight: '60rpx',
					borderRadius: '15rpx',
					margin: '0 20rpx',
				},
				carnumlist: [],
				carList: [],
				ischeckedAll: true,
				componeryArr: [],
				addressNew: null,
				Index: 0,
				diasabledInput: true, //可读不可写
				carNumberIpt: '', //车牌号
				nameIpt: '', //车主姓名
				phoneIpt: '', //联系方式
				tareIpt: '', //联系方式
				addCarLoginShow: false,
				carshow1: false,
				carshow: false,
				carType: '',
				typeid: '',
				isgk: false,
				isgkdata: 1,
				iszdcl: false,
				iszdcldata: 2,
				isjdwl: false,
				isjdwldata: 0,
				zxobj: {
					zhdz: '',
					xhdz: -1,
					xhdzName: '',
					ORMTB404ID: ''
				},
				msgobj: {
					dfzh:-1,
					wllx: -1,
					wlcj: -1,
					dfzhName: '',
					dfzhId: '',
					wlcjName: '',
					wlcjId: '',
					wlcjdId: '',
					wllxName: '',
					wllxId: '',
					wllxDj: '',
					kd: '',
					glf:'',
					cs: '',
					yf: '',
					cssj: '24',
					fdyf: ''
				},
				remark: '',
				dfzhArray: [],
				cjArray: [],
				xhArray: [],
				wlArray: [],
				page: 1,
				list1: [{
						name: '13米',
						checked: true,
						disabled: false
					},
					{
						name: '7米6',
						checked: false,
						disabled: false
					},
					{
						name: '9米6',
						checked: false,
						disabled: false
					}

				],
				zmcjdata: {
					cjxs: 0,
					cjwlxs: 0,
					cjname: '',
					cjwlname: ''
				},

				styleCellGroup: {
					'fontSize': '36rpx'
				},
				cx: '13米',
				list: [{
					phone: ''
				}],
				padingTop: '26vh',
				sendObj: {}
			}
		},
		onLoad(op) {
			this.getdfzhList()
			this.getOrderList()
			this.getxhOrderList()
			this.getRemark()
			this.valChange()
		},
		onShow() {
			let that = this;
			this.systemInfo = uni.getSystemInfoSync()
			this.navHeight = this.systemInfo.platform == 'ios' ? 64 : 68;
			//监听自定义事件
			uni.$on("handClickSelectAddress", res => {
				that.handClickSelectAddress(res);
				//清除监听，不清除会消耗资源
				uni.$off('handClickSelectAddress');
			})
			that.xhdzFun()
			// if (uni.getStorageSync('sendobj')) {

			// 	let itemObj = JSON.parse(uni.getStorageSync('sendobj'))
			// 	setTimeout(() => {
			// 		this.msgobj.wlcj = 0
			// 		this.msgobj.wllx = 0
			// 		this.zmcjdata.cjname = itemObj.ORMTB440CA05
			// 		this.zmcjdata.cjwlname = itemObj.ORMTB440CA07

			// 		this.msgobj.wlcjName = this.zmcjdata.cjname
			// 		this.msgobj.wlcjId = itemObj.ORDTB400CA09
			// 		this.msgobj.wlcjdId = itemObj.ORMTB440CA23


			// 		this.msgobj.wllxName = this.zmcjdata.cjwlname
			// 		this.msgobj.wllxId = itemObj.ORDTB400CA04
			// 		this.msgobj.wllxDj = itemObj.ORMTB440CA08
			// 		this.queryGwcList()


			// 	}, 1000)

			// 	if(itemObj.carList){
			// 		this.iszdcl = true
			// 		this.iszdcldata = 1
			// 		itemObj.carList.forEach(item => {
			// 			var carObj = {
			// 				carPlate: item.ORDTB400CA01, //车牌号
			// 			}
			// 			setTimeout(() => {

			// 				var j = (this.carnumlist || []).findIndex((profile) => profile.name === item.ORDTB400CA01);
			// 				this.carnumlist[j].checked = true

			// 			}, 3000)
			// 			this.carList.push(carObj)
			// 		})
			// 		uni.removeStorageSync('sendobj')
			// 	}
			// 	else{
			// 		this.iszdcl = false
			// 	}




			// }


		},
		//取值后，数据返回在这里


		mounted() {

		},

		methods: {

			carcustom() {
				this.carSearch = ''
				uni.navigateTo({
					url: '/pages/vehicleAddCar/index'
				})
			},
			focusFun() {
				this.padingTop = '30vh'
			},
			blurFun() {
				this.padingTop = '26vh'
			},
			bindPickerdfzhChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.msgobj.dfzh = e.detail.value
			
				this.msgobj.dfzhName = this.dfzhArray[this.msgobj.dfzh].ZHNAME
				this.msgobj.dfzhId = this.dfzhArray[this.msgobj.dfzh].ZHID
			},
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.msgobj.wlcj = e.detail.value


				this.zmcjdata.cjxs = 1
				this.zmcjdata.cjwlname = ''
				this.msgobj.wlcjName = this.cjArray[this.msgobj.wlcj].SETTB99CA00
				this.msgobj.wlcjId = this.cjArray[this.msgobj.wlcj].SETTB99ID
				this.msgobj.wlcjdId = this.cjArray[this.msgobj.wlcj].SETTB100ID
				this.queryGwcList()
				this.msgobj.wllx = -1



			},
			bindxhPickerChange: function(e) {
				console.log(this.xhArray)

				if (this.xhArray.length == 0) {
					uni.showToast({
						title: '请先添加收货地',
						type: 'default',
						icon: 'none'
					})

				} else {
					this.zxobj.xhdz = e.detail.value
					this.zxobj.xhdzName = this.xhArray[this.zxobj.xhdz].ORMTB404CA00
					this.zxobj.ORMTB404ID = this.xhArray[this.zxobj.xhdz].ORMTB404ID
				}


			},
			bindPickerWlChange(e) {

				this.msgobj.wllx = e.detail.value
				console.log('物料', this.msgobj.wllx)
				this.msgobj.wllxName = this.wlArray[this.msgobj.wllx].settb109CA00
				this.msgobj.wllxId = this.wlArray[this.msgobj.wllx].settb109ID
				this.msgobj.wllxDj = this.wlArray[this.msgobj.wllx].settb109CA01
				console.log(this.wlArray[this.msgobj.wllx].settb109ID)
				this.zmcjdata.cjxs = 2

			},

			// 选中某个单选框时，由radio时触发
			radioChange(e) {
				// console.log(e);
			},
			radioGroupChange(e) {
				// console.log(e);
			},
			change(e) {
				console.log('change', e);
				this.isgk = e
				if (this.isgk == true) {
					this.isgkdata = 2
				} else {
					this.isgkdata = 1
				}
				console.log(this.isgkdata)
			},
			changecl(e) {
				console.log('change', e);
				this.iszdcl = e
				if (this.iszdcl == true) {
					this.iszdcldata = 1

				} else {
					this.iszdcldata = 2
					this.carList = []
					// const resultArray = this.carList.filter(item => !this.carnumlist.includes(item));

					this.carnumlist.forEach(function(element) {
						element.checked = false
					});
				}
				// console.log(this.iszdcldata)
			},
			changejdwl(e) {
				console.log('change', e);
				this.isjdwl = e
				if (this.isjdwl == true) {
					this.isjdwldata = 1
				} else {
					this.isjdwldata = 0
				}
				console.log(this.isjdwldata)

			},
			
			
			// 代发运单账户列表
			getdfzhList() {
				uni.showLoading({
					title: '请求中...',
					mask: true
				});
				uni.request({
					url: this.baseUrl + '/orm/ormtb410/selectYfAccount',
					method: 'POST',
					dataType: 'json',
					data: {
						// SETTB403CA00: this.userinfo.PERTB005ID,
						// ORMTB410ID: this.userinfo.ORMTB410ID,
						// ORMTB400ID: this.userinfo.ORMTB400ID, //一级客户ID
						// SETTB99CA00: '', //二级企业名称
						// SETTB100CA04: this.cityCode, //市代码
						// page: this.page,
						// limit: 100,
					},
					success: (res) => {
						uni.hideLoading();
						if (res.data.code == 200) {
							if (!res.data.data || res.data.data == null) {
								this.dfzhArray = []
								// this.page = 1
								return
							}
							var data = res.data.data || []
							console.log(data)
							this.dfzhArray = data
						} else {
							this.dfzhArray = []
							// this.page = 1
							uni.showToast({
								title: res.data.message,
								type: 'default',
								icon: false
							})
						}
					},
					fail: (res) => {
						uni.hideLoading();
						uni.showToast({
							title: '服务器连接超时',
							type: 'default',
							icon: false
						})
					}
				});
			},
			

			// 企业列表
			getOrderList() {
				uni.showLoading({
					title: '请求中...',
					mask: true
				});
				uni.request({
					url: this.baseUrl + '/set/settb99/selectPageList',
					method: 'POST',
					dataType: 'json',
					data: {
						SETTB403CA00: this.userinfo.PERTB005ID,
						ORMTB410ID: this.userinfo.ORMTB410ID,
						ORMTB400ID: this.userinfo.ORMTB400ID, //一级客户ID
						SETTB99CA00: '', //二级企业名称
						SETTB100CA04: this.cityCode, //市代码
						page: this.page,
						limit: 100,
					},
					success: (res) => {
						uni.hideLoading();
						if (res.data.code == 200) {
							if (!res.data.data || res.data.data == null) {
								this.cjArray = []
								this.page = 1
								return
							}
							var data = res.data.data || []
							// console.log(data)
							this.cjArray = data
						} else {
							this.cjArray = []
							this.page = 1
							uni.showToast({
								title: res.data.message,
								type: 'default',
								icon: false
							})
						}
					},
					fail: (res) => {
						uni.hideLoading();
						uni.showToast({
							title: '服务器连接超时',
							type: 'default',
							icon: false
						})
					}
				});
			},

			handClickSelectAddress(item) {

				if (Object.keys(item).length > 0) {
					// const item = JSON.parse(decodeURIComponent(op.data));
					// // console.log(op)
					// // console.log(item)
					// this.xhdzqhID = item.ORMTB404ID
					this.xhdztitle = item
					console.log(this.xhdztitle, 'xhdztitle')
				}
			},

			xhdlistFun() {
				console.log(this.xhdztitle.ORMTB404CA00)
				if (this.xhdztitle.ORMTB404CA00) {
					uni.navigateTo({
						url: "/pages/deliveryPlace/index?ID=" + this.xhdztitle.ORMTB404ID
					})
				} else {
					uni.navigateTo({
						url: "/pages/deliveryPlace/index"
					})
				}


			},

			getRemark() {
				uni.showLoading({
					title: '请求中...',
					mask: true
				});
				uni.request({
					url: this.baseUrl + '/orm/ormtb460/getRemark',
					method: 'POST',
					dataType: 'json',
					success: (res) => {
						uni.hideLoading();
						if (res.data.code == 200) {
							var data = res.data.data || []
							// console.log(data)
							this.remark = res.data.data
							console.log(res)
						} else {
							uni.showToast({
								title: res.data.message,
								type: 'default',
								icon: false
							})
						}
					},
					fail: (res) => {
						uni.hideLoading();
						uni.showToast({
							title: '服务器连接超时',
							type: 'default',
							icon: false
						})
					}
				});
			},

			// 收货地址列表
			getxhOrderList() {
				uni.showLoading({
					title: '请求中...',
					mask: true
				});
				if (this.userinfo.sign == 'CUS-1') {
					var ORMTB400ID = this.userinfo.ORMTB400ID
				} else if (this.userinfo.sign == 'CUS-2' || this.userinfo.sign == 'CUS-3') {
					var ORMTB400ID = this.userinfo.ORMTB410ID
				}
				uni.request({
					url: this.baseUrl + '/orm/ormtb404/selectPageList',
					method: 'POST',
					dataType: 'json',
					data: {
						ORMTB400ID: ORMTB400ID,
						sign: this.userinfo.sign,
						page: this.page,
						limit: 1000,
					},
					success: (res) => {
						uni.hideLoading();
						if (res.data.code == 200) {
							if (!res.data.data || res.data.data == null) {
								this.xhArray = []
								this.page = 1
								return
							}
							var data = res.data.data || []
							// console.log(data)
							this.xhArray = data
						} else {
							this.xhArray = []
							this.page = 1
							uni.showToast({
								title: res.data.message,
								type: 'default',
								icon: false
							})
						}
					},
					fail: (res) => {
						uni.hideLoading();
						uni.showToast({
							title: '服务器连接超时',
							type: 'default',
							icon: false
						})
					}
				});
			},
			// 物料列表
			queryGwcList() {
				uni.showLoading({
					title: '加载中...',
					mask: true
				});
				// this.materList=[]
				var ORMTB410ID = ''
				if (this.userinfo.sign == "CUS-2" || this.userinfo.sign == 'CUS-3') {
					ORMTB410ID = this.userinfo.ORMTB410ID
				}
				uni.request({
					url: this.baseUrl + '/orm/ormtb440/selectAllSettb109',
					method: 'POST',
					dataType: 'json',
					data: {
						SETTB99ID: this.msgobj.wlcjId, //二级企业代码
						ORMTB410ID: ORMTB410ID,
						sign: this.userinfo.sign,
					},
					success: (res) => {
						// console.log(res);
						uni.hideLoading();
						if (res.data.code == 200) {
							// this.materList=res.data.data||[]
							this.wlArray = res.data.data || []
							console.log(this.wlArray)

						} else {
							uni.showToast({
								title: res.data.success,
								type: 'default',
								icon: false
							})
						}
					},
					fail: (res) => {
						uni.hideLoading();
						uni.showToast({
							title: res.errMsg,
							type: 'default',
							icon: false
						})
					}
				});
			},


			addItem() {
				if (this.list.length == 3) {
					uni.showToast({
						title: '最多三个',
						icon: 'none'
					})
					return false
				}
				// let add = {
				// 	id: parseInt(this.id) + 1
				// }
				this.list.push({
					phone: ''
				})
				// this.id = parseInt(this.id) + 1
				// this.phoneIpt += parseInt(this.id) + 1
				console.log(this.list)
			},
			// delItem(item) {
			// 	if (this.list.length == 1) {
			// 		uni.showToast({
			// 			title: '不能删除第1个',
			// 			icon: 'none'
			// 		})
			// 		return false;
			// 	}
			// 	this.list = this.list.filter((i) => {
			// 		return i != item
			// 	})
			// },
			carValChange(val) {
				// 将每次按键的值拼接到carNumberIpt变量中，注意+=写法
				this.carNumberIpt += val;
			},
			carBackspace() {
				// 删除carNumberIpt的最后一个字符
				if (this.carNumberIpt.length) this.carNumberIpt = this.carNumberIpt.substr(0, this.carNumberIpt.length -
					1);
			},
			delCar(item) {
				// this.carList = this.carList.filter((i) => {
				// 	return i != item
				// })
				// console.log(item)
				var i = (this.carList || []).findIndex((profile) => profile.carPlate === item.carPlate);
				this.carList.splice(i, 1)
				var j = (this.carnumlist || []).findIndex((profile) => profile.name === item.carPlate);
				// console.log(this.carnumlist[j])


				if (this.carnumlist[j]) return this.carnumlist[j].checked = false


			},
			boardClick() {
				this.carshow1 = true
			},
			carShowFun() {
				this.carshow = true
				// this.valChange()
			},
			checkedAll() {
				this.carnumlist.map(val => {
					val.checked = true
				})
				this.ischeckedAll = false
			},
			nocheckedAll() {
				this.carnumlist.map(val => {
					val.checked = false
				})
				this.ischeckedAll = true
			},
			determineFun() {
				this.carnumlist.forEach(item => {
					if (item.checked == true) {
						var i = (this.carList || []).findIndex((profile) => profile.carPlate === item.name);
						if (i == '-1') {
							console.log(item.name)
							var carObj = {
								carPlate: item.name, //车牌号
							}
							this.carList.push(carObj)
							console.log(this.carList)
						}
					}
				})
				this.carshow = false
			},
			sucAdd(e) {
				console.log(this.carNumberIpt)
				//车牌号
				var regC =
					/^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领])|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][0-9]{2}([0-9]|[A-Z]){5}))$/;
				// var regP = /^1[3-9][0-9]{9}$/;



				if (!regC.test(this.carNumberIpt)) return uni.showToast({
					title: '车牌号格式不正确，请检查',
					duration: 5000,
					icon: 'none',
				});
				else {
					this.carList.push({
						// checked: false,
						carPlate: this.carNumberIpt
					})
					console.log(this.carList)
					this.carNumberIpt = ''
				}



			},
			carclose() {
				this.carSearch = ''
			},
			checkboxGroupChange() {
				var arr = []
				this.carnumlist.map(val => {
					if (val.checked == true) {
						arr.push(arr)
					}
				})
				if (arr.lenth == this.carnumlist.length) {
					this.ischeckedAll = false
				} else {
					this.ischeckedAll = true
				}
			},
			xhdzFun() {
				uni.showLoading({
					title: '请求中...',
					mask: true
				});
				if (this.userinfo.sign == 'CUS-1') {
					var ID = this.userinfo.ORMTB400ID
				} else if (this.userinfo.sign == 'CUS-2' || this.userinfo.sign == 'CUS-3') {
					var ID = this.userinfo.ORMTB410ID
				}
				uni.request({
					url: this.baseUrl + '/orm/ormtb404/selectDefault',
					method: 'POST',
					dataType: 'json',
					data: {
						ORMTB410ID: ID,
						ORMTB404ID: this.xhdztitle.ORMTB404ID
					},
					success: (res) => {
						console.log(res);
						if (res.data.code == 200) {

							if (!res.data.data) {
								console.log('111')
								this.xhdztitle = {}
							} else {
								this.xhdztitle = res.data.data
							}


						} else {
							uni.showToast({
								title: res.errMsg,
								type: 'default',
								icon: false
							})
						}
						uni.hideLoading();
					},
					fail: (res) => {
						uni.hideLoading();
						uni.showToast({
							title: res.errMsg,
							type: 'default',
							icon: false
						})
					}
				});
			},
			valChange() { //输入input发生变化
				this.carnumlist = []
				this.carSearch = this.carSearch.toUpperCase()
				uni.showLoading({
					title: '请求中...',
					mask: true
				});
				if (this.userinfo.sign == 'CUS-1') {
					var ID = this.userinfo.ORMTB400ID
				} else if (this.userinfo.sign == 'CUS-2' || this.userinfo.sign == 'CUS-3') {
					var ID = this.userinfo.ORMTB410ID
				}
				uni.request({
					url: this.baseUrl + '/set/settb402/selectSettb402BySign',
					method: 'POST',
					dataType: 'json',
					data: {
						sign: this.userinfo.sign,
						SETTB402CA00: this.carSearch,
						ID: ID
					},
					success: (res) => {
						// console.log(res);
						if (res.data.code == 200) {
							var data = res.data.data
							this.carnumlist = []
							data.forEach(item => {
								this.carnumlist.push({
									checked: false,
									name: item.SETTB402CA00,
									disabled: false,
								})
							})
						} else {

						}
						uni.hideLoading();
					},
					fail: (res) => {
						uni.hideLoading();
						uni.showToast({
							title: res.errMsg,
							type: 'default',
							icon: false
						})
					}
				});

			},
			tareIptInput() { //限制验证码长度
				if (this.tareIpt.length > 6) {
					this.tareIpt = this.tareIpt.slice(0, 6)
				}
			},
			phoneIptInput() {
				if (this.phoneIpt.length > 11) {
					this.phoneIpt = this.phoneIpt.slice(0, 11)
				}
			},
			// 确定
			determine() {

				if (!this.xhdztitle) {
					return uni.showToast({
						title: '请选择收货地',
						duration: 5000,
						icon: 'none',
					});
				}

				if (this.xhdztitle.ORMTB404CA00 == '') {
					return uni.showToast({
						title: '请选择收货地',
						duration: 5000,
						icon: 'none',
					});
				}
				if (this.msgobj.wlcj == -1) {
					return uni.showToast({
						title: '请选择厂家',
						duration: 5000,
						icon: 'none',
					});
				}
				if (this.msgobj.wllx == -1) {
					return uni.showToast({
						title: '请选择物料',
						duration: 5000,
						icon: 'none',
					});
				}
				// if (this.iszdcl == false) {
				if (this.msgobj.cs == '') {
					return uni.showToast({
						title: '请输入车数',
						duration: 5000,
						icon: 'none',
					});
				}
				// }

				if (this.msgobj.fdyf == '') {
					return uni.showToast({
						title: '请输入发单运费价',
						duration: 5000,
						icon: 'none',
					});
				}
				if (this.msgobj.yf == '') {
					return uni.showToast({
						title: '请输入接单运费价',
						duration: 5000,
						icon: 'none',
					});
				}


				if (this.msgobj.kd == '') {
					return uni.showToast({
						title: '请输入所承担的亏吨范围',
						duration: 5000,
						icon: 'none',
					});
				}
				if (this.msgobj.cssj == '') {
					return uni.showToast({
						title: '请输入超时自动取消时间',
						duration: 5000,
						icon: 'none',
					});
				}
				if (this.iszdcl == true) {
					if (this.carList.length == 0) {
						return uni.showToast({
							title: '选择车辆',
							duration: 5000,
							icon: 'none',
						});
					}
				}


				if (Number(this.msgobj.fdyf) < Number(this.msgobj.yf)) {

					return uni.showToast({
						title: '发单运费价必须大于等于接单运费价',
						duration: 5000,
						icon: 'none',
					});
				}



				//车牌号
				// var regC =
				// 	/^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领])|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][0-9]{2}([0-9]|[A-Z]){5}))$/;
				// var regP = /^1[3-9][0-9]{9}$/;

				// for (let index = 0; index < this.list.length; index++) {
				// 	if (this.list[index].phone == '') {
				// 		return uni.showToast({
				// 			title: '请输入手机号',
				// 			duration: 5000,
				// 			icon: 'none',
				// 		});
				// 	}
				// 	if (this.list[index].phone != '') {
				// 		if (!regP.test(this.list[index].phone)) return uni.showToast({
				// 			title: '手机号格式不正确，请检查',
				// 			duration: 5000,
				// 			icon: 'none',
				// 		});
				// 	}
				// }
				// if(this.phoneIpt ==''){
				// 	return uni.showToast({
				// 		title: '请输入手机号',
				// 		duration: 5000,
				// 		icon: 'none',
				// 	});
				// }

				// if (this.tareIpt == '') {
				// 	return uni.showToast({
				// 		title: '请输入皮重',
				// 		duration: 5000,
				// 		icon: 'none',
				// 	});
				// }


				this.addCarLoginShow = true

			},

			addCarNewConfirm() {
				if (this.userinfo.sign == 'CUS-1') {
					var ORMTB400ID = this.userinfo.ORMTB400ID
				} else if (this.userinfo.sign == 'CUS-2' || this.userinfo.sign == 'CUS-3') {
					var ORMTB400ID = this.userinfo.ORMTB410ID
				}
				uni.request({
					url: this.baseUrl + '/orm/ormtb460/createFreight',
					method: 'POST',
					dataType: 'json',
					data: {
						ORMTB460CA00: this.zxobj.zhdz, //装货地址
						ORMTB460CA01: this.xhdztitle.ORMTB404CA00, //卸货地址
						ORMTB460CA02: this.cx, //车型
						ORMTBZS410ID: this.msgobj.dfzhId, //代发账户ID
						ORMTB460CA34: this.msgobj.glf, //管理费比例
						ORMTB460CA03: this.msgobj.wlcjId, //厂家ID
						ORMTB460CA14: this.msgobj.wlcjdId, //厂家短ID
						ORMTB460CA04: this.msgobj.wlcjName, //厂家名称
						ORMTB460CA05: this.msgobj.wllxId, //物料ID
						ORMTB460CA06: this.msgobj.wllxName, //物料名称
						ORMTB460CA07: this.msgobj.wllxDj, //物料单价
						ORMTB460CA08: this.msgobj.cs, //车数
						ORMTB460CA09: this.msgobj.yf, //接单运费单价
						ORMTB460CA26: this.msgobj.fdyf, //发单运费单价
						ORMTB460CA25: this.msgobj.kd, //亏吨范围
						ORMTB460CA20: this.xhdztitle.ORMTB404ID, //地址ID
						ORMTB460CA27: this.msgobj.cssj, //超时自动取消时间
						ORMTB460CA30: this.iszdcldata, //是否指定车牌
						ORMTB460CA31: this.isgkdata, //是否公开
						ORMTB460CA32: this.isjdwldata, //是否冻结接单物料
						ormtb461List: this.carList, //指定车牌号
						// sign: this.userinfo.sign,
						ORMTB410ID: ORMTB400ID,
					},
					success: (res) => {
						console.log(res);
						if (res.data.code == 200) {
							uni.showToast({
								title: '发布成功',
								duration: 5000,
								icon: 'none',
							});
							uni.navigateBack()
						} else {
							uni.showToast({
								title: res.data.message,
								duration: 5000,
								icon: 'none',
							});
						}
					},
					fail: (res) => {
						uni.showToast({
							title: res.data.message,
							duration: 5000,
							icon: 'none',
						});
					}
				});
			},

			// 重置
			reset() {
				this.carNumberIpt = '' //车牌号
				this.nameIpt = '' //车主姓名
				this.phoneIpt = '' //联系方式
				this.tareIpt = ''
			},
		}
	}
</script>

<style scoped>
	.addCar input {
		border: 0;
	}

	.addCar {
		width: 100%;
		min-height: 100vh;
		background-color: rgba(242, 242, 242, 1);
		overflow: hidden;
	}

	/* 列表 */

	/* 内容 */
	.addCar-content-box {
		/* width: 100%; */
		background: rgba(255, 255, 255, 1);
		padding: 10rpx 24rpx;
		margin: 20rpx;
		border-radius: 20rpx;
		box-shadow: 4rpx 4rpx 20rpx #e5e5e5;
	}

	.addCar-carName-phone {
		border-bottom: 2rpx solid rgba(230, 230, 230, 0.5);
		padding: 18rpx 0;
		/* font-size: 36rpx; */
	}

	.addCar-input-one {
		width: 310rpx !important;
		display: inline-block;
		margin-bottom: 0 !important;
		padding: 0 !important;
		height: 44rpx !important;
		vertical-align: middle;
		/* margin-left: 0.1rem; */
		color: rgba(51, 51, 51, 1);
		font-size: 32rpx;
		text-align: center;
	}

	.addCar-phone {
		width: 228rpx;
		display: inline-block;
		font-size: 32rpx;
		color: rgba(102, 102, 102, 1);
		vertical-align: middle;
		/* background: #000000; */
	}

	.addCar-phone-placeholder {
		font-size: 30rpx;
		color: rgba(102, 102, 102, .5);
	}

	.addCar-dun {
		color: rgba(51, 51, 51, 1);
		font-size: 30rpx;
	}

	/* 按钮 */
	.addCar-reset-determine {
		margin-top: 130rpx;
		display: flex;
		justify-content: center;
		padding-bottom: 60rpx;
	}



	.addCar-reset-determine>view {
		width: 80%;
		text-align: center;
		line-height: 100rpx;
		color: rgba(255, 255, 255, 1);
		font-size: 32rpx;
		border-radius: 20rpx;
	}

	.addCar-reset {
		width: 159rpx;
		background: rgba(234, 197, 15, 1);
		text-align: center;
		/* margin-left: 170rpx; */
		margin: 0 20rpx;
	}

	.addCar-determine {
		background: rgba(0, 161, 244, 1);
		/* margin-left: 60rpx; */
	}

	.add-phone-main {
		position: relative;
	}

	.add-phone {
		position: absolute;
		top: 20rpx;
		right: 0;
		/* font-size: 50rpx; */
		color: rgba(0, 255, 127, 1);
		/* background: rgba(0, 255, 127, 1); */

	}

	.addCar-phone-car {
		display: inline-block;
		width: 310rpx;
		height: 44rpx;
		line-height: 44rpx;
		/* border: 1px solid rgba(0, 0, 0, .2); */
		/* border-radius: 3px; */
		text-align: center;
		vertical-align: middle;
		font-size: 30rpx;
	}

	input::placeholder {
		color: rgba(102, 102, 102, .5);
	}

	.item-box {
		display: flex;
	}

	.zhuang-huo-dizhi {
		background-color: #303133;
		color: #fff;
		border-radius: 50%;
		width: 50rpx;
		height: 50rpx;
		display: inline-block;
		font-size: 32rpx;
		text-align: center;
		margin-right: 10rpx;
		margin-bottom: 20rpx;
	}

	.xie-huo-dizhi {
		background-color: #2979ff;
		color: #fff;
		border-radius: 50%;
		width: 50rpx;
		height: 50rpx;
		line-height: 50rpx;
		display: inline-block;
		font-size: 32rpx;
		text-align: center;
		margin-right: 10rpx;
		margin-left: 20rpx;
		margin-top: 24rpx;
	}

	.zx-addres {
		background: rgba(255, 255, 255, 1);
		border-radius: 20rpx;
		box-shadow: 4rpx 4rpx 20rpx #e5e5e5;
		/* padding: 20rpx 24rpx; */
		/* padding-bottom: 30rpx; */
		display: flex;
		/* border-bottom: 2rpx solid rgba(230, 230, 230, 1); */
		margin: 20rpx;
		justify-content: flex-start;

	}

	.cx-box {
		display: flex;
		justify-content: flex-start;
		padding: 18rpx 0;
	}

	.text-jieshao {
		color: red;
		padding: 10rpx 24rpx;
	}

	.iscar-nav {
		position: fixed;
		top: 0;
		width: 100%;
		/* height: 22vh; */
		/* box-sizing: border-box; */
		z-index: 2;
		background-color: #FFF;
	}

	.iscar-content {
		/* margin-top: 24vh; */
	}

	.iscar-nav-top {
		height: 10vh;
		/* background-color: #e3e3e3; */
	}

	.iscar-nav-search {
		display: flex;
		/* background-color: #e3e3e3; */
		padding-bottom: 20rpx;
	}

	.iscar-nav-search-ipt {
		flex: 1;
	}

	.iscar-nav-search-btn {
		width: 100rpx;
		height: 60rpx;
		line-height: 60rpx;
		/* font-size: 28rpx; */
		text-align: center;
		color: #333;
		margin: 0 20rpx;
	}

	.iscar-nav-btn {
		display: flex;
		justify-content: space-between;
		height: 90rpx;
		line-height: 90rpx;
		font-size: 36rpx;
		color: #333;
		padding: 0 40rpx;
		border-top: 2rpx solid #e3e3e3;
		border-bottom: 2rpx solid #e3e3e3;
		background-color: #fff;
	}

	.iscar-nav-btn view+view {
		color: #02a2f4;
	}

	.iscar-nav-btn view {
		/* width: 100rpx; */
		text-align: center;
	}

	.iscar-content {
		padding-left: 30rpx;
	}

	.xhdz-xinxi {
		width: 87%;
		background: #fff;
		border-radius: 10px;
		display: flex;
		justify-content: space-between;
	}

	.xh-text {
		background: #fff;
		border-radius: 20rpx 0 0 20rpx;
		margin-left: 10rpx;
	}

	/* .uni-picker-container .uni-picker-item{
		font-size: 40rpx !important;
	} */
</style>
